import numpy as np

def demonstrate_numpy_string_functions():
    """
    NumPy字符串函数演示脚本
    包含菜鸟教程链接中的所有字符串函数知识点
    """
    
    print("=== NumPy字符串函数演示 ===\n")
    
    # 1. numpy.char.add() - 字符串连接
    print("1. add() - 字符串连接")
    print("连接两个字符串:")
    result_add1 = np.char.add(['hello'], ['xyz'])
    print(f"np.char.add(['hello'], ['xyz']) = {result_add1}")
    
    print("连接两个数组:")
    result_add2 = np.char.add(['hello', 'hi'], ['abc', 'xyz'])
    print(f"np.char.add(['hello', 'hi'], ['abc', 'xyz']) = {result_add2}\n")
    
    # 2. numpy.char.multiply() - 多重连接
    print("2. multiply() - 多重连接")
    result_multiply = np.char.multiply('Runoob', 3)
    print(f"np.char.multiply('Runoob', 3) = {result_multiply}\n")
    
    # 3. numpy.char.center() - 字符串居中
    print("3. center() - 字符串居中")
    result_center = np.char.center('Runoob', 20, fillchar='*')
    print(f"np.char.center('Runoob', 20, fillchar='*') = {result_center}\n")
    
    # 4. numpy.char.capitalize() - 首字母大写
    print("4. capitalize() - 首字母大写")
    result_capitalize = np.char.capitalize('runoob')
    print(f"np.char.capitalize('runoob') = {result_capitalize}\n")
    
    # 5. numpy.char.title() - 每个单词首字母大写
    print("5. title() - 每个单词首字母大写")
    result_title = np.char.title('i like runoob')
    print(f"np.char.title('i like runoob') = {result_title}\n")
    
    # 6. numpy.char.lower() - 转换为小写
    print("6. lower() - 转换为小写")
    result_lower1 = np.char.lower(['RUNOOB', 'GOOGLE'])
    print(f"np.char.lower(['RUNOOB', 'GOOGLE']) = {result_lower1}")
    
    result_lower2 = np.char.lower('RUNOOB')
    print(f"np.char.lower('RUNOOB') = {result_lower2}\n")
    
    # 7. numpy.char.upper() - 转换为大写
    print("7. upper() - 转换为大写")
    result_upper1 = np.char.upper(['runoob', 'google'])
    print(f"np.char.upper(['runoob', 'google']) = {result_upper1}")
    
    result_upper2 = np.char.upper('runoob')
    print(f"np.char.upper('runoob') = {result_upper2}\n")
    
    # 8. numpy.char.split() - 字符串分割
    print("8. split() - 字符串分割")
    result_split1 = np.char.split('i like runoob?')
    print(f"np.char.split('i like runoob?') = {result_split1}")
    
    result_split2 = np.char.split('www.runoob.com', sep='.')
    print(f"np.char.split('www.runoob.com', sep='.') = {result_split2}\n")
    
    # 9. numpy.char.splitlines() - 按行分割
    print("9. splitlines() - 按行分割")
    result_splitlines1 = np.char.splitlines('i\nlike runoob?')
    print(f"np.char.splitlines('i\\nlike runoob?') = {result_splitlines1}")
    
    result_splitlines2 = np.char.splitlines('i\rlike runoob?')
    print(f"np.char.splitlines('i\\rlike runoob?') = {result_splitlines2}\n")
    
    # 10. numpy.char.strip() - 移除首尾字符
    print("10. strip() - 移除首尾字符")
    result_strip1 = np.char.strip('ashok arunooba', 'a')
    print(f"np.char.strip('ashok arunooba', 'a') = {result_strip1}")
    
    result_strip2 = np.char.strip(['arunooba', 'admin', 'java'], 'a')
    print(f"np.char.strip(['arunooba', 'admin', 'java'], 'a') = {result_strip2}\n")
    
    # 11. numpy.char.join() - 连接字符串
    print("11. join() - 连接字符串")
    result_join1 = np.char.join(':', 'runoob')
    print(f"np.char.join(':', 'runoob') = {result_join1}")
    
    result_join2 = np.char.join([':', '-'], ['runoob', 'google'])
    print(f"np.char.join([':', '-'], ['runoob', 'google']) = {result_join2}\n")
    
    # 12. numpy.char.replace() - 字符串替换
    print("12. replace() - 字符串替换")
    result_replace = np.char.replace('i like runoob', 'oo', 'cc')
    print(f"np.char.replace('i like runoob', 'oo', 'cc') = {result_replace}\n")
    
    # 13. numpy.char.encode() - 字符串编码
    print("13. encode() - 字符串编码")
    result_encode = np.char.encode('runoob', 'cp500')
    print(f"np.char.encode('runoob', 'cp500') = {result_encode}\n")
    
    # 14. numpy.char.decode() - 字符串解码
    print("14. decode() - 字符串解码")
    encoded_str = np.char.encode('runoob', 'cp500')
    result_decode = np.char.decode(encoded_str, 'cp500')
    print(f"编码结果: {encoded_str}")
    print(f"解码结果: np.char.decode(encoded_str, 'cp500') = {result_decode}\n")
    
    print("=== 演示结束 ===")

if __name__ == "__main__":
    demonstrate_numpy_string_functions()